/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package comunicatorserver;

import comunicatorserver.irc.MyIRCEventListener;
import comunicatorserver.mail.SendMails;
import comunicatorserver.mobilecall.SendShortCall;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.schwering.irc.lib.IRCConnection;

/**
 *
 * @author Ricardo
 */
public class ComunicatorServer {


    private IRCConnection conn;

    private SendMails sendMails;
    private SendShortCall sendShortCalls;


    public ComunicatorServer(){


         sendMails= new SendMails("");

         sendShortCalls= new SendShortCall("./sendtoque /dev/ttyUSB2 <num> 10");

       
        
          conn = new IRCConnection(
                            "127.0.0.1",
                            6667,
                            6669,
                            "",
                            "CServer",
                            "Foobar",
                            "foobarcom"
                          );

          


        conn.addIRCEventListener(new MyIRCEventListener(this));
        conn.setDaemon(false);
        conn.setColors(false);
        conn.setPong(true);


         try {
           conn.connect(); // Try to connect!!! Don't forget this!!!
           //conn.doJoin("#BarreirasACS");
           conn.doJoin("#BarreirasACSToques");
           //doPrivmsg(java.lang.String target, java.lang.String msg)

         } catch (IOException ioexc) {
           ioexc.printStackTrace();
         }


        System.out.println("\n\n----fez tudo---------------------------------------------------------------------------------------------------------------------------------------------------------\n\n");




    }


    public void sendNotifications(String arg1){

        
        sendMails= new SendMails(arg1);
        sendShortCalls= new SendShortCall("./sendtoque /dev/ttyUSB2 <num> 10");


        sendMails.start();
        sendShortCalls.start();

        
        try {
            sendMails.join();
        } catch (InterruptedException ex) {
            System.out.println("\nsendMails.join();------------------");

            Logger.getLogger(ComunicatorServer.class.getName()).log(Level.SEVERE, null, ex);
        }

        try {
            sendShortCalls.join();
        } catch (InterruptedException ex) {
            System.out.println("\nsendShortCalls.join();------------------");
            Logger.getLogger(ComunicatorServer.class.getName()).log(Level.SEVERE, null, ex);
        }


        sendMails=null;
        sendShortCalls=null;
        
        System.gc();
         
    }




}
